package com.ruoyi.project.cms.mm.delay.serivce;

import com.ruoyi.project.cms.mm.delay.domain.Delay;
import com.ruoyi.project.cms.mm.delay.mapper.DelayMapper;
import com.ruoyi.project.cms.mm.task.domain.TaskInfo;
import com.ruoyi.project.cms.mm.task.mapper.TaskInfoMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * @author Administrator
 * @create 2020-05-18 15:00
 * @desc 任务延期实现类
 **/
@Service
public class DelayServiceImpl implements DelayService {
    @Autowired
    private DelayMapper delayMapper;
    @Autowired
    private TaskInfoMapper taskInfoMapper;
    @Override
    public List<Delay> selectMoreDelays(Delay delay) {
        return delayMapper.selectMore(delay);
    }

    @Override
    public int insert(Delay delay) {
        return delayMapper.insert(delay);
    }

    @Override
    public int deleteDelayBydid(String ids) {
        return delayMapper.deleteByDid(ids);
    }

    @Override
    public Delay selectDelayByDid(Integer did) {
        return delayMapper.selectByDid(did);
    }

    @Override
    public int updateDelay(Delay delay) {
        return delayMapper.update(delay);
    }

    @Override
    public List<Delay> selectDelaysByNext(Delay delay) {
        return delayMapper.selectByNext(delay);
    }

    @Override
    public Delay selectDelayDetailByDid(Integer did) {
        return delayMapper.selectDelayDetailByDid(did);
    }

    @Override
    public int apprvDelay(Delay delay) {
//        对审批意见进行判断
        if(delay.getOpinion() == 1) {
//            同意
//            1.更新taskInfo表的end_date
            TaskInfo info = new TaskInfo();
            info.setTid(delay.getTid());
            info.setEnd_date(delay.getDdate());
            taskInfoMapper.update(info);
//            2.更新审批状态
            delay.setStatus(2);
            return delayMapper.updateApprv(delay);
        } else {
            delay.setStatus(3);
            return delayMapper.updateApprv(delay);
        }
    }

    @Override
    public List<Delay> selectDelaysByNextAndStatus(Delay delay) {
        return delayMapper.selectDelayDetailByNextAndStatus(delay.getNextauditor());
    }
}
